package com.nexgo.payment.trans.preauthcomnotify;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.nexgo.payment.R;
import com.nexgo.payment.action.inputauthcode.InputAuthCodeFragment;
import com.nexgo.payment.action.inputdate.InputDateFragment;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.trans.AbsTransActivity;
import com.nexgo.payment.util.ActivityUtils;

/**
 * 预授权完成通知
 * Created by wanghongyang on 2017/8/24.
 */
public class PreAuthComNotifyActivity extends AbsTransActivity<PreAuthComNotifyContract.Presenter> implements PreAuthComNotifyContract.View{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new PreAuthComNotifyPresenter(this, Repository.getInstance());
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.start();
    }

    @Override
    public void showInputDate() {
        InputDateFragment inputDateFragment = InputDateFragment.newInstance();
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.contentFrame);
        if (fragment == null) {
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), inputDateFragment, R.id.contentFrame);
        } else {
            ActivityUtils.replaceFragmentToActivity(getSupportFragmentManager(), inputDateFragment, R.id.contentFrame);
        }
    }

    @Override
    public void showInputAuthCode() {
        InputAuthCodeFragment authCodeFragment = InputAuthCodeFragment.newInstance();
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.contentFrame);
        if (fragment == null) {
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), authCodeFragment, R.id.contentFrame);
        } else {
            ActivityUtils.replaceFragmentToActivity(getSupportFragmentManager(), authCodeFragment, R.id.contentFrame);
        }
    }

    public static Intent newInstance(Context context) {
        return new Intent(context, PreAuthComNotifyActivity.class);
    }
}
